<template>
  <div class="login-container">
    <NavBar title="登录"></NavBar>
    <div class="loginContain">
      <h3>欢迎使用高校管理系统</h3>
      <h4>请先登录</h4>
      <van-form @submit="onSubmit">
        <van-field
          v-model="username"
          name="用户名"
          label="用户名"
          placeholder="用户名"
        />
        <van-field
          v-model="password"
          type="password"
          name="密码"
          label="密码"
          placeholder="密码"
        />
        <div style="margin: 16px">
          <van-button round block type="info" native-type="submit"
            >登录</van-button
          >
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import router from "@/router";
import NavBar from "@/components/navBar.vue";
import { Notify } from "vant";
export default {
  components: {
    NavBar,
  },
  data() {
    return {
      username: "",
      password: "",
      // 通知栏状态及信息
      state: "danger",
      msg: "",
    };
  },
  methods: {
    // 左上角返回
    onClickLeft() {
      router.back();
    },
    // 账号密码校验
    onSubmit(values) {
      if (this.username === "admin" && this.password === "123456") {
        this.state = "success";
        this.msg = "登陆成功";
        localStorage.setItem("Token", "Bearer");
        router.back();
      } else {
        this.msg = "帐号或者密码不正确";
      }
      Notify({ type: this.state, message: this.msg });
    },
  },
};
</script>

<style lang='less' scoped>
* {
  margin: 0;
  padding: 0;
}
.van-nav-bar {
  background-color: orange;
}
/deep/.van-nav-bar__title {
  color: white;
}
/deep/.van-nav-bar .van-icon {
  color: white;
}
.loginContain {
  display: flex;
  justify-content: center;
  align-items: center;
  height: calc(100vh - 46px);
  padding-top: 46px;
  flex-direction: column;
  background-color: #e6e3e3;
  h4 {
    margin-top: 20px;
    margin-bottom: 15px;
  }
}
</style>